package com.ruoyi.web.controller.shop.common;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.common.core.domain.ShopRegion;
import com.ruoyi.shop.common.core.service.IShopRegionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行政地区Controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */
@Controller
@RequestMapping("/shop/region")
public class ShopRegionController extends BaseController
{
    private String prefix = "shop/comm/region";

    @Autowired
    private IShopRegionService shopRegionService;

    @RequiresPermissions("core:region:view")
    @GetMapping()
    public String region()
    {
        return prefix + "/region";
    }

    /**
     * 查询行政地区列表
     */
    @RequiresPermissions("core:region:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopRegion shopRegion)
    {
        startPage();
        List<ShopRegion> list = shopRegionService.selectRegionList(shopRegion);
        return getDataTable(list);
    }

    /**
     * 导出行政地区列表
     */
    @RequiresPermissions("core:region:export")
    @Log(title = "行政地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopRegion shopRegion)
    {
        List<ShopRegion> list = shopRegionService.selectRegionList(shopRegion);
        ExcelUtil<ShopRegion> util = new ExcelUtil<ShopRegion>(ShopRegion.class);
        return util.exportExcel(list, "行政地区数据");
    }

    /**
     * 新增行政地区
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行政地区
     */
    @RequiresPermissions("core:region:add")
    @Log(title = "行政地区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopRegion shopRegion)
    {
        return toAjax(shopRegionService.insertRegion(shopRegion));
    }

    /**
     * 修改行政地区
     */
    @RequiresPermissions("core:region:edit")
    @GetMapping("/edit/{regionId}")
    public String edit(@PathVariable("regionId") Long regionId, ModelMap mmap)
    {
        ShopRegion shopRegion = shopRegionService.selectRegionById(regionId);
        mmap.put("shopRegion", shopRegion);
        return prefix + "/edit";
    }

    /**
     * 修改保存行政地区
     */
    @RequiresPermissions("core:region:edit")
    @Log(title = "行政地区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopRegion shopRegion)
    {
        return toAjax(shopRegionService.updateRegion(shopRegion));
    }

	/**
	 * 删除行政地区
	 */
	@RequiresPermissions("core:region:remove")
	@Log(title = "行政地区", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(shopRegionService.deleteRegionByIds(ids));
	}
}
